#include "Log.h"

void Log(char *string)
{
	//Get the current time
	time_t currentTime = time(0);
	tm *now = localtime(&currentTime);

	int year = (now->tm_year + 1900);
	char month[4];
	switch(now->tm_mon)
	{
	case 0:
		std::strcpy(month, "Jan");
		break;

	case 1:
		std::strcpy(month, "Feb");
		break;

	case 2:
		std::strcpy(month, "Mar");
		break;

	case 3:
		std::strcpy(month, "Apr");
		break;

	case 4:
		std::strcpy(month, "May");
		break;

	case 5:
		std::strcpy(month, "Jun");
		break;

	case 6:
		std::strcpy(month, "Jul");
		break;

	case 7:
		std::strcpy(month, "Aug");
		break;

	case 8:
		std::strcpy(month, "Sep");
		break;

	case 9:
		std::strcpy(month, "Oct");
		break;

	case 10:
		std::strcpy(month, "Nov");
		break;

	case 11:
		std::strcpy(month, "Dec");
		break;
	}
	int day = now->tm_mday;
	int hour = now->tm_hour;
	int min = now->tm_min;
	int sec = now->tm_sec;

	//Append the time then string to a log file
	std::fstream file;

	file.open("log.txt", std::fstream::in | std::fstream::out | std::fstream::app);
	if(!file.bad())
		file << year << " " << month << " " << day << " " << hour << ":" << min << ":" << sec << "   " << string << std::endl;

	file.close();
}

void Log(const char *string)
{
	//Get the current time
	time_t currentTime = time(0);
	tm *now = localtime(&currentTime);

	int year = (now->tm_year + 1900);
	char month[4];
	switch(now->tm_mon)
	{
	case 0:
		std::strcpy(month, "Jan");
		break;

	case 1:
		std::strcpy(month, "Feb");
		break;

	case 2:
		std::strcpy(month, "Mar");
		break;

	case 3:
		std::strcpy(month, "Apr");
		break;

	case 4:
		std::strcpy(month, "May");
		break;

	case 5:
		std::strcpy(month, "Jun");
		break;

	case 6:
		std::strcpy(month, "Jul");
		break;

	case 7:
		std::strcpy(month, "Aug");
		break;

	case 8:
		std::strcpy(month, "Sep");
		break;

	case 9:
		std::strcpy(month, "Oct");
		break;

	case 10:
		std::strcpy(month, "Nov");
		break;

	case 11:
		std::strcpy(month, "Dec");
		break;
	}
	int day = now->tm_mday;
	int hour = now->tm_hour;
	int min = now->tm_min;
	int sec = now->tm_sec;

	//Append the time then string to a log file
	std::fstream file;

	file.open("log.txt", std::fstream::in | std::fstream::out | std::fstream::app);
	if(!file.bad())
		file << year << " " << month << " " << day << " " << hour << ":" << min << ":" << sec << "   " << string << std::endl;

	file.close();
}
